$(function() {
	var Owidth = $(document).width();
	$('html').css('font-size', Owidth / 10 + 'px');

	function GetQueryString(name) {
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
		var r = window.location.search.substr(1).match(reg);
		if(r != null) return unescape(r[2]);
		return null;
	}
	var uid = GetQueryString("uid");
	if(uid == null) {
		window.location.href = "fail1";
	}
	if(uid!==null){
			uploat();
	}
	

	function uploat() {
		$('#tel').on('input', function() {
			$('.c1').show();
			$('.tel1').css("border-bottom", "1px solid red");
			if($('#tel').val() == '') {
				$('.tel1').css("border-bottom", "1px solid #ccc");
				$('.c1').hide();
			}
			if($('#tel').val().length == 11) {
				$('.tel1').css("border-bottom", "1px solid green");
			}
		});
		$('.c1').click(function() {
			$('#tel').val('');
			$('.tel1').css("border-bottom", "1px solid #ccc");
			$('.c1').hide();
		});

		$('#tel1').on('input', function() {
			$('.c2').show();
			$('.tel2').css("border-bottom", "1px solid red");
			if($('#tel1').val() == '') {
				$('.tel2').css("border-bottom", "1px solid #ccc");
				$('.c2').hide();
			}
			if($('#tel1').val().length == 6) {
				$('.tel2').css("border-bottom", "1px solid green");
			}
		});
		$('.c2').click(function() {
			$('#tel1').val('');
			$('.tel2').css("border-bottom", "1px solid #ccc");
			$('.c2').hide();
		});

		$('#pass').on('input', function() {
			$('.c3').show();
			$('.tel3').css("border-bottom", "1px solid red");
			if($('#pass').val() == '') {
				$('.tel3').css("border-bottom", "1px solid #ccc");
				$('.c3').hide();
			}
			if($('#pass').val().length >= 8) {
				$('.tel3').css("border-bottom", "1px solid green");
			}
		});
		$('.c3').click(function() {
			$('#pass').val('');
			$('.tel3').css("border-bottom", "1px solid #ccc");
			$('.c3').hide();
		});
		/*仿刷新：检测是否存在cookie*/
		if($.cookie("captcha")) {
			var count = $.cookie("captcha");
			var btn = $('#btn1');
			btn.val(count + 'S').attr('disabled', true).css('cursor', 'not-allowed');
			var resend = setInterval(function() {
				count--;
				if(count > 0) {
					btn.val(count + 'S').attr('disabled', true).css('cursor', 'not-allowed');
					$.cookie("captcha", count, {
						path: '/',
						expires: (1 / 86400) * count
					});
				} else {
					clearInterval(resend);
					btn.val("获取验证码").removeClass('disabled').removeAttr('disabled style');
				}
			}, 1000);
		}

		function judge() {
			/*点击改变按钮状态，已经简略掉ajax发送短信验证的代码*/
			var btn = $('#btn1');
			var count = 60;
			var resend = setInterval(function() {
				count--;
				if(count > 0) {
					btn.val(count + "S");
					$.cookie("captcha", count, {
						path: '/',
						expires: (1 / 86400) * count
					});
				} else {
					clearInterval(resend);
					btn.val("获取验证码").removeAttr('disabled style');
				}
			}, 1000);
			btn.attr('disabled', true).css('cursor', 'not-allowed');
		}

		$('#btn1').click(function() {
			var tel = $('#tel').val();
			var T = {
				values: {
					"tel": tel,
					"action": "REGISTER_ACCOUNT"
				}
			};
			$.ajax({
				type: "get",
				url: "http://www.topsydy.com/app/sydy/account/register/getAutoCode",
				async: true,
				data: T.values,
				success: function(data) {
					var data1 = JSON.parse(data);
					alert(data1.msg);
					if(data1.code == 0) {
						var reg = /(1[3-9]\d{9}$)/;
						if(jQuery('#tel').val() == "") {
							jQuery('#tel').focus();
							return false;
						}
						//正则表达式
						else if(!reg.test(jQuery('#tel').val())) {
							jQuery('#tel').focus();
							alert("请输入正确格式的手机号码！");
							$('#tel').val('');
							$('.c1').hide();
							return false;
						}
					}
					if(data1.code == 1) {
						judge();
					}
				}
			});
		});

		$('.register').click(function() {

			var A = $('#tel').val();
			var B = $('#tel1').val();
			var C = $('#pass').val();
			var F = {
				values: {
					"tel": A,
					"authCode": B,
					"passd": C,
					"refereeUid": uid,
				}
			};

			$.ajax({
				type: "get",
				url: "http://www.topsydy.com/app/sydy/account/register",
				async: true,
				data: F.values,
				success: function(data) {
					var data2 = JSON.parse(data);
					if(data2.code == 0) {
						alert("注册失败!请检查您的注册信息");
					}
					if(data2.code == 1) {
						downloadApp();
					}
				}
			});
		});

		function downloadApp() {
			var u = navigator.userAgent;
			var ua = navigator.userAgent.toLowerCase();
			var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端 
			var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端 
			if(ua.match(/MicroMessenger/i) == "micromessenger") { //微信内置浏览器
					window.location.href = "success1";

			} else {
				if(isiOS) {
						window.location.href = 'http://downloadpkg.apicloud.com/app/download?path=http://7zzc70.com1.z0.glb.clouddn.com/57fa438252adb558a01a51aa0d5cbdc9_d&ver=0.0.0&size=3.17M'
					
				} else if(isAndroid) {
						window.location.href = 'https://www.apicloud.com/getIpa/d2a623771e8429b6c7f77fb58bf3ac7e'
				} else {
						window.location.href = 'http://downloadpkg.apicloud.com/app/download?path=http://7zzc70.com1.z0.glb.clouddn.com/57fa438252adb558a01a51aa0d5cbdc9_d&ver=0.0.0&size=3.17M'

				}

			}

		};

		$.ajax({
			type: "get",
			url: "http://www.topsydy.com/app/sydy/account/userinfo/getinfo?uid=" + uid,
			async: true,
			dataType: 'json',
			success: function(data) {
				$('.recom span').html(data.msg.nickname);
			}
		});
	};
});